package com.company;
import java.util.Arrays;
public class Main {
    public static int firstMissingPositive(int[] nums){
        int n = nums.length;
        int contain=0;

        System.out.println(Arrays.toString(nums));

        for (int i=0;i<n;i++) {
            if(nums[i]==1){contain++;
            break;}
        }
        if(contain == 0)return 1;
        if(n == 1)return 2;

        for(int i=0;i<n;i++){
            if(nums[i]<=0 || nums[i]>n){
                nums[i] = 1;
            }
        }
        System.out.println(Arrays.toString(nums));
        int temp;
        for(int i=0;i<n;i++){
            temp = Math.abs(nums[i]);

            if(temp == n){
                nums[0] = -Math.abs(nums[0]);
            }else {
                nums[temp] = -Math.abs(nums[temp]);
            }
        }
        System.out.println(Arrays.toString(nums));
        for(int i=1;i<n;i++){
            if(nums[i]>0){
                return i;
            }
        }
        if(nums[0] > 0)return n;
        return n+1;
    }
    public static void main(String[] args) {
        // write your code here
        System.out.println("Hello World");
        //int[] b = {3,4,-1,-2,1,10,5,0,2,0};
        int[] b = {7,8,9,11,12};
        System.out.println(firstMissingPositive(b));
    }
}
